package com.zyf.chapter02.creation.singleton.refactor;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * 单例日志类
 * @author yifeng
 */
public class Logger {
    private FileWriter writer;
    private static final Logger instance=  new Logger();

    private Logger() {
        File file = new File("/user/yifeng/log.txt");
        // true 表示追加写入
        try {
            writer = new FileWriter(file, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public static Logger getInstance() {
        return instance;
    }

    public void log(String message) throws IOException {
        writer.write(message);
    }

}
